package com.cleaningcloud.cld.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.cleaningcloud.cld.domain.CldPayConfirm;
import com.cleaningcloud.cld.domain.dto.CldPayDetailsDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.cld.domain.CldPayDetails;
import com.cleaningcloud.cld.service.ICldPayDetailsService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 薪酬管理Controller
 * 
 * @author cleaningcloud
 * @date 2024-11-08
 */
@RestController
@RequestMapping("/CldPayDetails")
public class CldPayDetailsController extends BaseController
{
    @Autowired
    private ICldPayDetailsService cldPayDetailsService;

    /**
     * 查询薪酬管理列表
     */
    @RequiresPermissions("cld:CldPayDetails:list")
    @GetMapping("/list")
    public TableDataInfo list(CldPayDetails cldPayDetails)
    {
        startPage();
        List<CldPayDetails> list = cldPayDetailsService.selectCldPayDetailsList(cldPayDetails);
        return getDataTable(list);
    }

    /**
     * 导出薪酬管理列表
     */
    @RequiresPermissions("cld:CldPayDetails:export")
    @Log(title = "薪酬管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CldPayDetails cldPayDetails)
    {
        List<CldPayDetails> list = cldPayDetailsService.selectCldPayDetailsList(cldPayDetails);
        ExcelUtil<CldPayDetails> util = new ExcelUtil<CldPayDetails>(CldPayDetails.class);
        util.exportExcel(response, list, "薪酬管理数据");
    }

    /**
     * 获取薪酬管理详细信息
     */
    @RequiresPermissions("cld:CldPayDetails:query")
    @GetMapping(value = "/{payDetailsId}")
    public AjaxResult getInfo(@PathVariable("payDetailsId") Long payDetailsId)
    {
        return success(cldPayDetailsService.selectCldPayDetailsByPayDetailsId(payDetailsId));
    }

    /**
     * 薪资头部统计
     */
    @GetMapping(value = "/salaryHeadStatistics")
    public AjaxResult salaryHeadStatistics()
    {
        return success(cldPayDetailsService.salaryHeadStatistics());
    }

    /**
     * 新增薪酬管理
     */
    @RequiresPermissions("cld:CldPayDetails:add")
    @Log(title = "薪酬管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldPayDetails cldPayDetails)
    {
        return toAjax(cldPayDetailsService.insertCldPayDetails(cldPayDetails));
    }

    /**
     * 修改薪酬管理
     */
    @RequiresPermissions("cld:CldPayDetails:edit")
    @Log(title = "薪酬管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldPayDetails cldPayDetails)
    {
        return toAjax(cldPayDetailsService.updateCldPayDetails(cldPayDetails));
    }



    /**
     * 修改薪酬管理
     */
    @RequiresPermissions("cld:CldPayDetails:edit")
    @Log(title = "薪酬管理", businessType = BusinessType.UPDATE)
    @PutMapping("/batchEdit")
    public AjaxResult batchEdit(@RequestBody List<CldPayDetails> list)
    {
        return toAjax(cldPayDetailsService.batchUpdateCldPayDetails(list));
    }

    /**
     * 删除薪酬管理
     */
    @RequiresPermissions("cld:CldPayDetails:remove")
    @Log(title = "薪酬管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{payDetailsIds}")
    public AjaxResult remove(@PathVariable Long[] payDetailsIds)
    {
        return toAjax(cldPayDetailsService.deleteCldPayDetailsByPayDetailsIds(payDetailsIds));
    }


    /**
     * 实时薪酬列表
     */
    @GetMapping("/selectRealTimeSalaryGrouping")
    public TableDataInfo selectRealTimeSalaryGrouping(CldPayDetailsDto cldPayDetails)
    {
        startPage();
        List<Map<String,Object>> list = cldPayDetailsService.selectRealTimeSalaryGrouping(cldPayDetails);
        return getDataTable(list);
    }


    /**
     * 累计薪酬列表
     */
    @GetMapping("/getCumulativeSalaryList")
    public TableDataInfo getCumulativeSalaryList(CldPayDetailsDto cldPayDetails)
    {
        startPage();
        List<Map<String,Object>> list = cldPayDetailsService.getCumulativeSalaryList(cldPayDetails);
        return getDataTable(list);
    }



    /**
     * 累计薪酬列表 - 按项目查看 - 待发薪酬
     * @param projectId
     * @return
     */
    @GetMapping(value = "/getCumulativeSalaryByProjectId")
    public AjaxResult getCumulativeSalaryByProjectId(CldPayConfirm cldPayConfirm)
    {
        return success(cldPayDetailsService.getCumulativeSalaryByProjectId(cldPayConfirm));
    }

    /**
     * 累计薪酬列表 - 按项目查看 - 实发薪酬
     */
    @GetMapping("/getCumulativeSalaryByProjectIdList")
    public TableDataInfo getCumulativeSalaryByProjectIdList(CldPayConfirm cldPayConfirm)
    {
        startPage();
        List<Map<String,Object>> list = cldPayDetailsService.getCumulativeSalaryByProjectId(cldPayConfirm);
        return getDataTable(list);
    }


    /**
     * 工资统计
     */
    @GetMapping("/selectSalaryStatistics")
    public TableDataInfo selectSalaryStatistics(CldPayDetailsDto cldPayDetails)
    {
        startPage();
        List<Map<String,Object>> list = cldPayDetailsService.selectSalaryStatistics(cldPayDetails);
        return getDataTable(list);
    }

    /**
     * 列表查看项目薪酬一览
     */
    @GetMapping(value = "/getTableCalendarList")
    public AjaxResult getTableCalendarList(CldPayDetailsDto cldPayDetailsDto)
    {
        return success(cldPayDetailsService.getTableCalendarList(cldPayDetailsDto));
    }

    /**
     * 日历查看员工薪酬一览
     */
    @GetMapping(value = "/getCalendarByStaffId")
    public AjaxResult getCalendarByStaffId(CldPayDetailsDto cldPayDetailsDto)
    {
        return success(cldPayDetailsService.getCalendarByStaffId(cldPayDetailsDto));
    }
}

